package com.nononsenseapps.feeder.processor

import com.nononsenseapps.feeder.db.room.AppDatabase
import com.nononsenseapps.feeder.db.entity.Feed
import com.nononsenseapps.feeder.db.entity.FeedItem
import java.io.IOException

fun interface Interceptor {
    @Throws(IOException::class)
    fun intercept(chain: Chain): FeedItem

    companion object {
        /**
         * Constructs an interceptor for a lambda. This compact syntax is most useful for inline
         * interceptors.
         *
         * ```kotlin
         * val interceptor = Interceptor { chain: Interceptor.Chain ->
         *     chain.proceed(chain.request())
         * }
         * ```
         */
        inline operator fun invoke(crossinline block: (chain: Chain) -> FeedItem): Interceptor =
            Interceptor { block(it) }
    }

    interface Chain {

        @Throws(IOException::class)
        fun proceed(feed: Feed, feedItem: FeedItem): FeedItem

        fun getFeed(): Feed

        fun getFeedItem(): FeedItem

        fun getAppDatabase():AppDatabase

        fun getRuleManager():RuleManager

        fun getProcessContext():ProcessContext
    }
}
